package com.st.controller;


import com.st.entity.*;
import com.st.mapper.IAreasMapper;
import com.st.mapper.ICityMapper;
import com.st.service.IAreasService;
import com.st.service.IAttractionsService;
import com.st.service.ICityService;
import com.st.service.IProvincesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/attraction")
public class AttractionController {
    @Autowired
    private IAttractionsService attractionsService;
    @Autowired
    private IProvincesService iProvincesService;
    @Autowired
    private ICityService iCityService;
    @Autowired
    private IAreasService iAreasService;

    @PostMapping("/search")
    public PageResult<Attractions> search(@RequestBody  PageDTO<Attractions> pageDTO){
        if (pageDTO == null) {
            pageDTO.setPage(1);
            pageDTO.setLimit(5);
        }
        return attractionsService.findAttractions(pageDTO);
    }
    @PostMapping("/delOne")
    public Result delByIds(@RequestBody Attractions attractions){
        return attractionsService.delAttraction(attractions);
    }
    @PostMapping("/updateOne")
    public Result updateOne(@RequestBody Attractions attractions){
        return attractionsService.updateAttraction(attractions);
    }
    @PostMapping("/insertOne")
    public Result insertOne(@RequestBody Attractions attractions){
        return attractionsService.addAttraction(attractions);
    }
    @PostMapping("/findAllProvinces")
    public List<Provinces> insertOne(){
        return iProvincesService.findAllProvinces();
    }
    @RequestMapping("/findCityList")
    public List<City> findCityList(@RequestBody Provinces provinces){
        String provinceid = provinces.getProvinceid();
        return iCityService.findCityByPId(provinceid);
    }
    @RequestMapping("/findAreasList")
    public List<Areas> findAreasList(@RequestBody City city){
        String cityid = city.getCityid();
        List<Areas> areasByCId = iAreasService.findAreasByCId(cityid);
        return areasByCId;
    }


}
